import 'package:json_annotation/json_annotation.dart';

part 'media_info_result.g.dart';

///"guid": "5c102b0f58ec43109021ef0ffbeef3b5",
///"lan": "",
///"douban_id": 0,
///"imdb_id": "",
///"tv_title": "新白娘子传奇",
///"parent_guid": "7f2d0af936174d0dab3ed75175b9c1ba",
///"parent_title": "",
///"title": "青白斗法收婢女",
///"type": "Episode",
///"poster": "/93/10/RXFg9YOlYYTNwMynBkZifbn3VpVnzd401lk1CjS099E0CKLruVglT90twLCoSKCqkBWLatiJ2O7lx0nfkXs149S8SF.webp",
///"poster_width": 1920,
///"poster_height": 1080,
///"runtime": 60,
///"is_favorite": 0,
///"watched": 0,
///"watched_ts": 0,
///"media_stream": {
///    "resolutions": null,
///    "audio_type": null,
///    "color_range_type": null
///},
///"season_number": 1,
///"episode_number": 1,
///"number_of_seasons": 0,
///"number_of_episodes": 0,
///"local_number_of_seasons": 0,
///"local_number_of_episodes": 0,
///"status": "",
///"ancestor_guid": "1757c4255b4143df848422bccb9a9977",
///"ancestor_name": "",
///"ancestor_category": "",
///"ts": 64,
///"duration": 3022,
///"single_child_guid": "",
///"media_guid": "e1f7964d068d4e20b3a2256f1cc38596",
///"audio_guid": "79422bfa94204c36bc7a3da6e9ae7a28",
///"video_guid": "a9d2cd93848a43b6ba2b9c6ec9b68177",
///"file_name": ""
@JsonSerializable()
class MediaInfoResult {
  final String guid;
  final String lan;
  @JsonKey(name: 'douban_id')
  final int doubanId;
  @JsonKey(name: 'imdb_id')
  final String imdbId;
  @JsonKey(name: 'tv_title')
  final String tvTitle;
  @JsonKey(name: 'parent_guid')
  final String parentGuid;
  @JsonKey(name: 'parent_title')
  final String parentTitle;
  final String title;
  final String type;
  final String? poster;
  @JsonKey(name: 'poster_width')
  final int? posterWidth;
  @JsonKey(name: 'poster_height')
  final int? posterHeight;
  final int? runtime;
  @JsonKey(name: 'is_favorite')
  final int isFavorite;
  final int watched;
  @JsonKey(name: 'watched_ts')
  final int watchedTs;
  @JsonKey(name: 'media_stream')
  final MediaStream mediaStream;
  @JsonKey(name: 'season_number')
  final int seasonNumber;
  @JsonKey(name: 'episode_number')
  final int episodeNumber;
  @JsonKey(name: 'number_of_seasons')
  final int numberOfSeasons;
  @JsonKey(name: 'number_of_episodes')
  final int numberOfEpisodes;
  @JsonKey(name: 'local_number_of_seasons')
  final int localNumberOfSeasons;
  @JsonKey(name: 'local_number_of_episodes')
  final int localNumberOfEpisodes;
  final String status;
  @JsonKey(name: 'ancestor_guid')
  final String? ancestorGuid;
  @JsonKey(name: 'ancestor_name')
  final String ancestorName;
  @JsonKey(name: 'ancestor_category')
  final String ancestorCategory;
  final int ts;
  final int duration;
  @JsonKey(name: 'single_child_guid')
  final String singleChildGuid;
  @JsonKey(name: 'media_guid')
  final String? mediaGuid;
  @JsonKey(name: 'audio_guid')
  final String? audioGuid;
  @JsonKey(name: 'video_guid')
  final String? videoGuid;
  @JsonKey(name: 'file_name')
  final String fileName;
  @JsonKey(name: 'release_date')
  final String? releaseDate;
  @JsonKey(name: 'air_date')
  final String? airDate;
  @JsonKey(name: 'first_air_date')
  final String? firstAirDate;
  @JsonKey(name: 'last_air_date')
  final String? lastAirDate;
  final String? overview;
  @JsonKey(name: 'vote_average')
  final String? voteAverage;

  factory MediaInfoResult.fromJson(Map<String, dynamic> json) {
    try {
      return _$MediaInfoResultFromJson(json);
    } catch (e, s) {
      print('Error: $json\n$e\n$s');
      rethrow;
    }
  }

  MediaInfoResult({
    required this.guid,
    required this.lan,
    required this.doubanId,
    required this.imdbId,
    required this.tvTitle,
    required this.parentGuid,
    required this.parentTitle,
    required this.title,
    required this.type,
    required this.poster,
    required this.posterWidth,
    required this.posterHeight,
    required this.runtime,
    required this.isFavorite,
    required this.watched,
    required this.watchedTs,
    required this.mediaStream,
    required this.seasonNumber,
    required this.episodeNumber,
    required this.numberOfSeasons,
    required this.numberOfEpisodes,
    required this.localNumberOfSeasons,
    required this.localNumberOfEpisodes,
    required this.status,
    required this.ancestorGuid,
    required this.ancestorName,
    required this.ancestorCategory,
    required this.ts,
    required this.duration,
    required this.singleChildGuid,
    required this.mediaGuid,
    required this.audioGuid,
    required this.videoGuid,
    required this.fileName,
    required this.releaseDate,
    required this.airDate,
    required this.firstAirDate,
    required this.lastAirDate,
    required this.overview,
    required this.voteAverage,
  });
}

@JsonSerializable()
class MediaStream {
  final List<String>? resolutions;
  @JsonKey(name: 'audio_type')
  final String? audioType;
  @JsonKey(name: 'color_range_type')
  final String? colorRangeType;

  MediaStream(this.resolutions, this.audioType, this.colorRangeType);

  factory MediaStream.fromJson(Map<String, dynamic> json) =>
      _$MediaStreamFromJson(json);
}
